﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Office.InfoPath;

namespace InfoPathDebugger.FormOpenProvider
{
    /// <summary>
    /// Open a normal InfoPath form.
    /// </summary>
    public class NormalFormOpenProvider : IFormOpenProvider
    {
        #region IFormOpenProvider Members

        public void Open(FormControl formControl, String filePath)
        {
            // Close the loaded InfoPath form.
            // Note: Close the form before clear InfoPath cache. Because some
            // files in the cache might be used in current InfoPath form, if the
            // form hasn't been closed, the files cannot be deleted.
            formControl.Close();

            // Clear the cache of InfoPath forms, prevent the version detect.
            InfoPathFormHelper.ClearInfoPathCache();

            // Open a new InfoPath form.
            formControl.NewFromFormTemplate(filePath);
        }

        #endregion
    }
}
